<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>

    <script src="js/mui.min.js"></script>
    <link href="css/mui.min.css" rel="stylesheet"/>
    <script type="text/javascript" charset="utf-8">
      	mui.init();
		mui.plusReady(function () {
		    
		})
		document.addEventListener("plusready", function() {
			// 页面加载完成后自动执行
		});

    </script>
</head>
<body>
	<header class="mui-bar mui-bar-nav">
		<a class="mui-icon mui-action-menu mui-icon-arrowleft mui-pull-left" onclick="mui.back()"></a>
		<h1 class="mui-title ">登录</h1>
		<a class="mui-btn mui-pull-right mui-btn-primary" href="reg.html">注册</a>
	</header>
	    <div class="mui-content">
	        <div class="login-container">
	            
	                <div class="mui-input-row">
	                    <label>账号</label>
	                    <input id="username" type="text" class="mui-input-clear" placeholder="请输入账号">
	                </div>
	                <div class="mui-input-row">
	                    <label>密码</label>
	                    <input id="password" type="password" class="mui-input-clear" placeholder="请输入密码">
	                </div>
	                <div class="mui-row">
	                    <button id='login' class="mui-btn mui-btn-block mui-btn-primary" onclick="loging()">登录</button>
	                </div>
<!-- 	                <div class="mui-row">
	                    <a href="javascript:;" class="mui-pull-right" onclick="toRegister()">注册账号</a>
	                </div> -->
	            
	        </div>
	    </div>
	
	
	    <script src="js/mui.min.js"></script>
		<script type="text/javascript" charset="utf-8">
		  	mui.init();
			
			
			
			
			mui.plusReady(function () {
				
			})
			document.addEventListener("plusready", function() {
				// 页面加载完成后自动执行
			});
			
			    function loging() {
			        var username = document.getElementById('username').value;
			        var password = document.getElementById('password').value;
			        var data = {
			            "user_id": username,
			            "password": password,
			        };
			        console.log('账号：' + username + '，密码：' + password);
			        //mui.toast('登录中,请稍等...');
			        var url = plus.storage.getItem("rw_server") + "/login"
			        console.log(url);
			    
			        //修正 fetch 请求的语法
					
			        fetch(url, {
			            method: "post",
			            headers: {
			                "Content-Type": "application/json"
			            },
			            body: JSON.stringify({
			                "user_id": username,
			                "password": password,
			            })
			        })
			        .then(response => response.json())
			        .then(data => {
			            console.log(JSON.stringify(data));
			                plus.storage.setItem("login_state", data["login"]);
			                plus.storage.setItem("real_name", String(data["real_name"]));
			                plus.storage.setItem("class_id", String(data["classs"]));
			                plus.storage.setItem("cla_name", String(data["cla_name"]));
							console.log(data["classs"]);
							console.log(plus.storage.getItem("class_id"));
			                mui.toast(data["prompt"]);
			                if(data["login"] == true){
								plus.storage.setItem("user_id", username);
								plus.storage.setItem("password", password);
								mui.openWindow({
			                    url: 'index.html',
			                    id: 'index',
			                });
							}
			        })
			        .catch(error => {
			            console.error('Error:', error);
			        });
			    }
			            
			    // function toRegister() {
			    //     // 跳转到注册页面的逻辑
			    //     console.log('跳转到注册页面');
			    // 	mui.openWindow({
			    // 		url :'reg.html',
			    // 		id :'111',
			    // 	})
			    // }
			            
			    function forgetPassword() {
			        // 跳转到忘记密码页面的逻辑
			        console.log('跳转到忘记密码页面');
			    }

			
		</script>
</body>
</html>